/*
 * Item.java
 * Team qq 2011
 */
package com.google.code.timetrail.backend;
/**
 * An interface that provides all that needs to be known about items
 * for things like inventory adding and removing 
 * @author Steven
 * @version 1.0
 */
public abstract class Item {
	
	/** The minimum amount of any item*/
	public static final int MIN_AMOUNT = 0;

	/** The current amount of that item in an instance*/
	protected int currentAmount;
	
	/**
	 *  Instantiate currentAmount
	 */
	public Item(){
		currentAmount = 0;
	}

	/**
	 * returns the weight of one unit of that item
	 * @return the item's weight
	 */
	public abstract int getWeight();
	
	/**
	 * returns the item's value
	 * @return the value in money for one unit of that item
	 */
	public abstract int getValue();
	
	/**
	 * provides a maximum amount of that item that can be in the inventory
	 * 
	 * @return the maximum amount of items 
	 */
	public abstract int getMaxAmount();
	
	/**
	 * returns the current amount of that item in a given instance
	 * @return the amount of items currently there
	 */
	public int getCurrentAmount(){
		return currentAmount;
	}

	/**
	 * set the current amount of the item, from min-max
	 * @param amount the amount to set the item to 
	 */
	public void setCurrentAmount(int amount){
		if(amount > getMaxAmount() || amount < MIN_AMOUNT){
			return;
		}
		else{
			this.currentAmount = amount;
		}
	}
		
	/**
	 * Does a test to add an item DOES NOT ACTUALLY ADD AN ITEM
	 * @param amount the amount to add in
	 * @return true for success and false for failure
	 */
	public boolean canAddCurrentAmount(int amount){
		if((amount + getCurrentAmount()) > getMaxAmount() 
				|| (amount + getCurrentAmount()) < MIN_AMOUNT){
			return false;
		}
		else{
			return true;
		}
	}
	
	/**
	 * Adds an amount to the number of items in that item instance
	 * @param amount the number of items to add
	 */
	public void addCurrentAmount(int amount){
		if((amount + getCurrentAmount()) > getMaxAmount() 
				|| (amount + getCurrentAmount()) < MIN_AMOUNT){
			return;
		}
		else{
			currentAmount += amount;
		}
	}

	/**
	 * acts as a wrapper to negative amounts in canAddCurrentAmount
	 * @param amount the amount to subtract
	 * @return true for success and false for failure
	 */
	public boolean canRemoveCurrentAmount(int amount){
		if(amount < 0){
			return false;
		}
		else{
			return canAddCurrentAmount((-1 * amount));
		}
	}

	/**
	 * Removes the amount from an instance of an item
	 * @param amount the amount to subtract
	 */
	public void removeCurrentAmount(int amount){
		if(amount < 0){
			return;
		}
		else{
			addCurrentAmount(-1 * amount);
		}
	}

	/**
	 * returns the name of that item
	 * @return the name of the item
	 */
	public abstract String getItemName();
	
	/**
	 * The string representation for an Item
	 * @return the item's name
	 */
	@Override
	public String toString(){
		return getItemName();
	}
	
}
